package net.chenyan.server.repository;/**
 * @author chenyan
 * @createTime 2022/5/5 14:03
 * @description description
 */

import net.chenyan.server.po.Album;
import net.chenyan.server.po.Mv;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Repository;

/**
 *@description: TODO
 *@author: chenyan
 *@create: 2022/5/5 14:03
 */
@Repository
public interface AlbumRepository extends PagingAndSortingRepository<Album,Integer>, JpaSpecificationExecutor<Album> {
    //分页模糊查询（根据mv名称分页模糊查询所有数据）
    @Query(value = "select *  from album a where a.name LIKE CONCAT('%',:name,'%')  ",nativeQuery = true) //分页表连接
    Page<Album> findByNameLike(Pageable pageable, String name);
    //分页查询（根据歌手姓名分页查询所有数据）
    @Query(value = "select *  from album  where singer_id=?1",nativeQuery = true)
    Page<Album> findBySingerName(int singerId,Pageable pageable);

    @Query(value = "select *  from album  order by liked_num desc",nativeQuery = true)
    Page<Album> findByLikedNum(Pageable pageable);

    @Query(value = "select *  from album  order by create_time desc",nativeQuery = true)
    Page<Album> findByCreateTime(Pageable pageable);

    //分页查询（根据用户id分页查询所有用户收藏的数据）
    @Query(value = "select a.*  from user_album ua inner join user u on u.id=ua.user_id inner join album a on a.id=ua.album_id where user_id=?1 and is_collect=1",nativeQuery = true)
    Page<Album> findAlbumByUserId(int userId, Pageable pageable);


}
